HTML API: Ensure set_modifiable_text includes special leading newlines#10879
HTML API: Ensure set_modifiable_text includes special leading newlines#10879sirreal wants to merge 20 commits intoWordPress:trunkfrom
Conversation
@todo split into data provider
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
dmsnell
left a comment
There was a problem hiding this comment.
I’ve added a new test, which asserts that this works during seek operations. I don’t know a great way to handle this apart from tracking every PRE location in the document, but the dependence on $this->skip_newline_at means that the last-parsed PRE must be the one immediately before the text node with set_modifiable_text().
for the HTML Processor this isn’t currently a problem because all seeks move forward from the start, but that’s not spec — that’s just a coincidence with the current implementation.
if we were to store the PRE locations then we could keep them updated with lexical updates, moving them around and deleting them in sync with changes, and that wouldn’t involve too much extra work for most documents.
| $set_text, | ||
| array( | ||
| "\r\n" => "\n", | ||
| "\r" => "\n", |
There was a problem hiding this comment.
given that the tests do not include carriage returns, is it worth adding this extra code in the test harness?
Detect cases where
::set_modifiable_text()would omit a leading newline from its input and adjust accordingly. This is done by adding an additional leading newline (that is ignored by HTML parsers) in case a leading newline is detected in the input.This follows the HTML parsing rules for TEXTAREA, PRE, and LISTING elements that ignores a single
U+000A LINE FEEDcharacter immediately following the open tag. It also respects the guidlines on newline normalization, so aU+000D CARRIAGE RETURNalso triggers the extra newline.Trac ticket: https://core.trac.wordpress.org/ticket/64609
Related ticket PR: #10871
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.